<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品名称" prop="goodName">
        <el-input
          v-model="queryParams.goodName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品编号" prop="goodNumber">
        <el-input
          v-model="queryParams.goodNumber"
          placeholder="请输入商品编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <!-- <el-form-item label="商品星星数" prop="goodStars">
        <el-input
          v-model="queryParams.goodStars"
          placeholder="请输入商品星星数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->



      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" >
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ax:axGood:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ax:axGood:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ax:axGood:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ax:axGood:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="axGoodList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" /> -->
      <el-table-column label="商品名称" align="center" prop="goodName" />
      <el-table-column label="商品编号" align="center" prop="goodNumber" />
      <el-table-column label="商品分类" align="center" prop="classifyName" />
      <!-- <el-table-column label="商品描述" :show-overflow-tooltip="true" align="center" prop="goodDesc" /> -->
      <el-table-column label="商品价格" align="center" prop="todayPrice"   width="180px">
         <!-- <template slot-scope="scope">
          <p >今日价：{{scope.row.todayPrice }}</p>
          <p> 起始价：{{scope.row.goodPrice }}</p>
          <p >提货价：{{scope.row.topPrice }}</p>
         </template> -->
      </el-table-column>
      <!-- <el-table-column label="共售" align="center" prop="goodCounts" /> -->
      <el-table-column label="商品图片" align="center" prop="goodImg" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.goodImg" :width="50" :height="50"/>
        </template>
      </el-table-column>
       <el-table-column label="商品参数" align="center" prop="goodParams" />
      <el-table-column label="详情图片" :show-overflow-tooltip="true"  align="center" prop="goodDetail" />
      
     
      <!-- <el-table-column label="抢购时间" align="center" prop="beginYmd"  width="200px">
          <template slot-scope="scope">
          <p >{{scope.row.beginYmd }}</p>
           <p >至：{{scope.row.endYmd }}</p>
         </template>
      </el-table-column>

       <el-table-column label="抢购结束时间" align="center" prop="endYmd" /> 
       <el-table-column label="所属场次" align="center" prop="axRound.roundName" />
      <el-table-column label="上涨费率" align="center" prop="dayIncreaseRate" >
         <template slot-scope="scope">
          <p >{{scope.row.dayIncreaseRate }}%</p>
         </template>
      </el-table-column> -->
      <!-- <el-table-column label="今天价格" align="center" prop="todayPrice" />
      <el-table-column label="昨天价格" align="center" prop="yesterdayPrice" />
      <el-table-column label="前天价格" align="center" prop="beforeYesterdayPrice" /> -->
      <!-- <el-table-column label="上限价格" align="center" prop="topPrice" /> -->
      <!-- <el-table-column label="状态" align="center" prop="status" /> -->
      <!-- <el-table-column label="商品库存" align="center" prop="todayGoodCount" />
      <el-table-column label="已售库存" align="center" prop="todaySellGoodCount" /> -->
       <el-table-column label="出售方"  :show-overflow-tooltip="true" align="center" prop="sellerInfo" />

      <el-table-column label="商品星星数" align="center" prop="goodStars" />
            <el-table-column label="状态" align="center" prop="status" >
           <template slot-scope="scope">
                <span v-if="scope.row.status=='1'"  style="color:green"> 已上架</span>
                 <span v-if="scope.row.status=='2'"  style="color:orange">已下架</span>
            </template>
      </el-table-column>


    <el-table-column label="可使用支付类型"  :show-overflow-tooltip="true" align="center" prop="ablePayType" >
                   <template slot-scope="scope">
                       <span v-if="scope.row.ablePayType==1">不限</span>
                       <span v-if="scope.row.ablePayType==2">余额</span>
                       <span v-if="scope.row.ablePayType==3">券</span>
                   </template>
      </el-table-column>

     <el-table-column label="显示类型"  :show-overflow-tooltip="true" align="center" prop="isShowAll" >
        <template slot-scope="scope">
                 <span v-if="scope.row.isShowAll==1">不限</span>
                  <span v-if="scope.row.isShowAll==2">只能在分类中显示</span>
                 </template>
      </el-table-column>





      <el-table-column label="创建时间" align="center" prop="createTime" width="100" />
      <!-- <el-table-column label="场次id" align="center" prop="roundId" /> -->
      <!-- <el-table-column label="委拍时间" align="center" prop="authorizationSellTime" />
       <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

              <el-button 
            v-if="scope.row.status=='2'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleStatusChange(scope.row)"
            v-hasPermi="['ax:axGood:edit']"
          >上架</el-button>


            <el-button 
            v-if="scope.row.status=='1'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleStatusChange(scope.row)"
            v-hasPermi="['ax:axGood:edit']"
          >下架</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ax:axGood:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ax:axGood:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="商品名称" prop="goodName">
          <el-input v-model="form.goodName" placeholder="请输入商品名称" style="width:250px" />
        </el-form-item>
        <el-form-item label="商品编号" prop="goodNumber">
          <el-input v-model="form.goodNumber" placeholder="请输入商品编号"  style="width:250px"  />
        </el-form-item>
        <el-form-item label="商品分类" prop="goodClassify">
               <el-select v-model="form.goodClassify" >
            <el-option
              v-for="item in axClassifyList"
              :key="item.id"
              :label="item.classifyName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品图片" prop="goodImg">
          <image-upload v-model="form.goodImg"/>
        </el-form-item>
         <el-form-item label="价格" prop="todayPrice">
          <el-input v-model="form.todayPrice" placeholder="请输入价格"  style="width:250px"  />
        </el-form-item>
        <el-form-item label="商品库存" prop="todayGoodCount">
          <el-input v-model="form.todayGoodCount" placeholder="请输入商品库存" style="width:250px"  />
        </el-form-item>

        <el-form-item label="可使用支付类型" prop="ablePayType"> 
               <el-radio v-model="form.ablePayType" :label="1">不限</el-radio>
                 <el-radio v-model="form.ablePayType" :label="2">余额</el-radio>
                   <el-radio v-model="form.ablePayType" :label="3">券</el-radio>
        </el-form-item>

        <el-form-item label="显示类型" prop="isShowAll">
               <el-radio v-model="form.isShowAll" :label="1">不限</el-radio>
                 <el-radio v-model="form.isShowAll" :label="2">只能在分类中显示</el-radio>
        </el-form-item>



        <el-form-item label="详情图片">
          <editor v-model="form.goodDetail" :min-height="192"/>
        </el-form-item>

         <el-form-item label="商品图">
          <editor v-model="form.markerImg" :min-height="192"/>
        </el-form-item>
        <el-form-item label="出售方信息">
          <editor v-model="form.sellerInfo" :min-height="192"/>
        </el-form-item>

        <el-form-item label="商品星数" prop="goodStars">
          <el-input v-model="form.goodStars" placeholder="请输入商品星星数" style="width:250px"  />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listAxGood, getAxGood, delAxGood, addAxGood, updateAxGood,platformBlist} from "@/api/ax/axGood";
import { listAxRound } from "@/api/ax/axRound";
import { listAxGoodClassify} from "@/api/ax/axGoodClassify";

export default {
  name: "AxGood",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品管理表格数据
      axGoodList: [],
      axRoundList: [],
      axClassifyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodName: null,
        goodNumber: null,
        goodClassify: null,
        goodDesc: null,
        goodPrice: null,
        goodCounts: null,
        goodImg: null,
        goodDetail: null,
        goodStars: null,
        dayBeginTime: null,
        dayEndTime: null,
        dayIncreaseRate: null,
        todayPrice: null,
        yesterdayPrice: null,
        beforeYesterdayPrice: null,
        topPrice: null,
        status: null,
        todayGoodCount: null,
        todaySellGoodCount: null,
        roundId: null,
        authorizationSellTime: null,
          goodType:1
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品管理列表 */
    getList() {
      this.loading = true;
      platformBlist(this.queryParams).then(response => {
        this.axGoodList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    //获得场次
    getRoundList(){
      listAxRound({}).then(response => {
        this.axRoundList = response.rows;
      });
    },
    // 获得分类
    getClassifyList(){
        listAxGoodClassify({}).then(response => {
        this.axClassifyList = response.rows;
      });
    },
        //上架操作
     handleStatusChange(row) {
      var statusForm={};
      statusForm.id=row.id;
      if(row.status === "1"){
        statusForm.status='2'
      }else{
        statusForm.status='1'
      }
      let text = row.status === "1" ? "下架" : "上架";

        updateAxGood(statusForm).then(response => {
             this.$modal.msgSuccess(text+"成功");
             this.open = false;
             this.getList();
         });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        goodName: null,
        goodNumber: null,
        goodClassify: null,
        goodDesc: null,
        goodPrice: null,
        goodCounts: null,
        goodImg: null,
        goodDetail: null,
        goodStars: null,
        updateTime: null,
        updateBy: null,
        createBy: null,
        createTime: null,
         goodParams: null,
        remark: null,
        dayBeginTime: '09:00:00',
        dayEndTime: '10:00:00',
        ablePayType: 1,
         isShowAll: 1,
        dayIncreaseRate: null,
        todayPrice: null,
        yesterdayPrice: null,
        beforeYesterdayPrice: null,
        topPrice: null,
        status: null,
        todayGoodCount: null,
        todaySellGoodCount: null,
        roundId: null,
        authorizationSellTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.getRoundList();
      this.getClassifyList();

      this.reset();
      this.open = true;
      this.title = "添加商品管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getRoundList();
      this.getClassifyList();
      this.reset();
      const id = row.id || this.ids
      getAxGood(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAxGood(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.endYmd='1900-01-01';
            addAxGood(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商品管理编号为"' + ids + '"的数据项？').then(function() {
        return delAxGood(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ax/axGood/export', {
        ...this.queryParams
      }, `axGood_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
